//package com.elh.serurity.config;
//
//import com.elh.serurity.fail.MyAuthenticationFailHandler;
//import com.elh.serurity.success.MyAuthenticationSuccessHandler;
//import com.elh.serurity.utils.WebUtil;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.http.HttpMethod;
////
////import cn.hutool.core.util.ArrayUtil;
////import com.baomidou.mybatisplus.core.toolkit.StringUtils;
////import com.elh.serurity.exceptions.VerificationExcepton;
////import com.elh.serurity.fail.MyAuthenticationFailHandler;
////import org.springframework.beans.factory.annotation.Autowired;
////import org.springframework.beans.factory.annotation.Value;
////import org.springframework.stereotype.Component;
////import org.springframework.web.filter.OncePerRequestFilter;
////
////import javax.servlet.FilterChain;
////import javax.servlet.ServletException;
////import javax.servlet.http.HttpServletRequest;
////import javax.servlet.http.HttpServletResponse;
////import javax.servlet.http.HttpSession;
////import java.io.IOException;
////import java.util.List;
////
/////**
//// * @author liulei
//// */
////@Component
////public class VerificationCodeFilter extends OncePerRequestFilter {
////
////    @Autowired
////    private MyAuthenticationFailHandler myAuthenticationFailHandler;
////
////    @Value("${nologin.url.path}")
////    private List<String> nologinUrl;
////
////
////    @Override
////    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
////        String uri = request.getRequestURI();
////        if(!nologinUrl.contains(uri)){
////            filterChain.doFilter(request,response);
////        }
////        else{
////            checkCode(request,response);
////            filterChain.doFilter(request,response);
////        }
////
////
////    }
////
////    private void checkCode(HttpServletRequest request, HttpServletResponse response) {
////        HttpSession session = request.getSession();
////        if(request.getRequestURI().endsWith("")){
////
////        }
////
////        String captcha = request.getParameter("captcha");
////        String sessionCaptcha = (String)session.getAttribute("captcha");
////        if(StringUtils.isNotBlank(sessionCaptcha)){
////            session.removeAttribute("captcha");
////        }
////        try {
////            if(!StringUtils.equals(captcha,sessionCaptcha)){
////                throw new VerificationExcepton("验证码错误");
////            }
////        } catch (VerificationExcepton verificationExcepton) {
////            verificationExcepton.printStackTrace();
////            try {
////                myAuthenticationFailHandler.onAuthenticationFailure(request,response,verificationExcepton);
////            } catch (IOException e) {
////                e.printStackTrace();
////            } catch (ServletException e) {
////                e.printStackTrace();
////            }
////        }
////    }
////}
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.NoOpPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
//import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * @author liulei
// **/
//@EnableWebSecurity
//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
//
//    @Autowired
//    private MyAuthenticationSuccessHandler myAuthenticationSuccessHandler;
//
//    @Autowired
//    private MyAuthenticationFailHandler myAuthenticationFailHandler;
////
////    @Autowired
////    private VerificationCodeFilter verificationCodeFilter;
//
//    /**
//     * 自定义用户认证逻辑
//     */
//    @Autowired
//    private UserDetailsService userDetailsService;
//
//    /**
//     * 基于普通表单
//     *
//     */
////    @Override
////    protected void configure(HttpSecurity http) throws Exception {
////        http.authorizeRequests().anyRequest().authenticated().and()
////                .formLogin()
////                .loginPage("/loginPage.html") // 登陆页面
////                .loginProcessingUrl("/login/auth") // 表单提交请求路径
////                .successHandler(myAuthenticationSuccessHandler) // 登陆成功的逻辑
////                .failureHandler(myAuthenticationFailHandler) // 登陆失败的逻辑
////                .permitAll()// 上面请求放行
////                .and().csrf().disable();
////    }
//
//    /**
//     * 需要权限认证
//     *
//     * @param http
//     * @throws Exception
//     */
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        http.authorizeRequests()
//                .antMatchers("/admin/api/**").hasRole("admin")
//                .antMatchers("/user/api/**").hasRole("user")
//                .antMatchers(
//                        "/api/**",
//                        "/**/*.jpg",
//                        "/favicon.ico",
//                        "/*.html",
//                        "/**/*.html",
//                        "/**/*.css",
//                        "/**/*.js")
//                .permitAll()
//                .anyRequest().authenticated().and().formLogin()
//
//                .loginPage("/loginPage.html") // 登陆页面
//                .loginProcessingUrl("/login/auth") // 表单提交请求路径
//                .successForwardUrl("/hello")// 登陆成功后的
//                .successHandler(myAuthenticationSuccessHandler) // 登陆成功的逻辑
//                .failureHandler(myAuthenticationFailHandler) // 登陆失败的逻辑
//                .permitAll()// 上面请求放行
//                .and().rememberMe()
//                .and().csrf().disable();
//        http.logout()
//                .logoutUrl("/logout")  // 注销登陆的请求地址,get 默认为get请求
//                .logoutSuccessUrl("/") // 注销成功后的调转地址
//                // 多个
////                .logoutRequestMatcher(new AntPathRequestMatcher("/logout1","POST"))
////                .logoutRequestMatcher(new AntPathRequestMatcher("/logout2","POST"))
//                .logoutSuccessHandler(new LogoutSuccessHandler() {
//                    @Override
//                    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
//                        System.out.println("注销登陆成功了");
//                        WebUtil.renderJson(response,"注销登陆成功了");
//                    }
//                }).invalidateHttpSession(true);// session失效
//        // 在执行前执行
////        http.addFilterBefore(verificationCodeFilter, UsernamePasswordAuthenticationFilter.class);
//    }
//
////    @Bean
////    public BCryptPasswordEncoder bCryptPasswordEncoder() {
////        return new BCryptPasswordEncoder();
////    }
//
//        @Bean
//    public PasswordEncoder bCryptPasswordEncoder() {
//        return NoOpPasswordEncoder.getInstance();
//    }
//
//    /**
//     * 身份认证接口
//     */
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception
//    {
//        auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
//    }
//}
